<template>
  <div class="will-page">
    <iframe
      :src="datas.shortUrl"
      frameborder="0"
      width="100%"
      height="440"
    ></iframe>
    <div class="tc will-btn">
      <a-button type="primary" v-if="btnVisable" @click="getWillResult"
        >点击查询刷脸结果</a-button
      >
    </div>
  </div>
</template>
<script>
import { getWillAuthResult } from "@/api/contract";
import socketDict from "@/dict/socket";
export default {
  props: {
    datas: {
      type: Object,
      default: () => {
        return {};
      }
    },
    visable: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return { btnVisable: false };
  },
  computed: {
    wsMsg() {
      return this.$store.state.socket && this.$store.state.socket.message;
    }
  },
  watch: {
    wsMsg(newVal) {
      let code = socketDict.code.contract;
      if (newVal.code === code.success.value) {
        this.msgHandling(code.success.desc);
      } else if (newVal.code === code.fail.value) {
        this.msgHandling(code.success.fail);
      }
    },
    visable(newVal) {
      if (newVal == true) {
        this.setBtnTime();
      }
    }
  },

  created() {
    if (this.visable) {
      this.setBtnTime();
    }
  },
  methods: {
    // 消息处理
    msgHandling(desc) {
      this.$message.success(desc);
      this.$emit("onCancelWillModal", false);
      this.$emit("initPage");
    },
    //设置按钮定时器
    setBtnTime() {
      this.btnVisable = false;
      let self = this;
      setTimeout(function() {
        self.btnVisable = true;
      }, 5000);
    },
    //获取刷脸状态
    getWillResult() {
      getWillAuthResult({
        bizId: this.datas.bizId
      }).then(res => {
        if (res.code == 0) {
          this.$message.success("刷脸成功");
          clearTimeout();
          this.$emit("onCancelWillModal", false);
        }
      });
    }
  },
  destroyed() {
    clearTimeout();
  }
};
</script>

<style lang="scss" scoped>
.will-btn {
  margin-top: 10px;
  font-size: 12px;
  height: 32px;
}
</style>
